#include <wx/wx.h>
#include <wx/slider.h>

class MyPanel : public wxPanel
{
public:
    MyPanel(wxFrame *parent);

    void OnPaint(wxPaintEvent &event);
    void OnScroll(wxScrollEvent &event);

    wxSlider *slider;
    int fill;
};

class Slider : public wxFrame
{
public:
    Slider(const wxString &title);

    MyPanel *panel;
};

const int ID_SLIDER = 100;

Slider::Slider(const wxString &title)
    : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition,
              wxSize(270, 220))
{
    panel = new MyPanel(this);
    Center();
}

MyPanel::MyPanel(wxFrame *parent)
    : wxPanel(parent, wxID_ANY)
{
    fill = 0;
    slider = new wxSlider(this, ID_SLIDER, 0, 0, 140, wxPoint(50, 30),
                          wxSize(-1, 140), wxSL_VERTICAL);

    Connect(ID_SLIDER, wxEVT_COMMAND_SLIDER_UPDATED,
            wxScrollEventHandler(MyPanel::OnScroll));
    Connect(wxEVT_PAINT, wxPaintEventHandler(MyPanel::OnPaint));
}

void MyPanel::OnScroll(wxScrollEvent &event)
{
    fill = slider->GetValue();
    Refresh();
}

void MyPanel::OnPaint(wxPaintEvent &event)
{
    wxPaintDC dc(this);

    wxPen pen(wxColour(212, 212, 212));
    dc.SetPen(pen);

    dc.DrawRectangle(wxRect(140, 30, 80, 140));

    wxBrush brush1(wxColour(197, 108, 0));
    dc.SetBrush(brush1);

    dc.DrawRectangle(wxRect(140, 30, 80, fill));
}

class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};

bool MyApp::OnInit()
{
    Slider *frame = new Slider("Slider");
    frame->Show(true);

    return true;
}

wxIMPLEMENT_APP(MyApp);
